package com.virtium.vpc.action.controller;

import java.util.ArrayList;
import java.util.Iterator;

import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcProductstatusDAO;
import com.virtium.vpc.hibernate.model.VpcProductstatus;

public class VpcProductstatusManager {
	private static ArrayList<VpcProductstatus> arrVpcProductstatus = null;

	public static ArrayList<VpcProductstatus> getAll() {
		try {
			if (arrVpcProductstatus != null && arrVpcProductstatus.size() > 0)
				return arrVpcProductstatus;
			VpcProductstatusDAO vpcProductstatusDAO = DAOFactory.getInstance()
					.getVpcProductstatusDAO();
			arrVpcProductstatus = new ArrayList<VpcProductstatus>();
			arrVpcProductstatus.addAll(vpcProductstatusDAO.findAll());
		} catch (Exception ex) {
		}
		return arrVpcProductstatus;
	}
	
	public static String getTextByID(int id){
		getAll();
		Iterator<VpcProductstatus> iterObject = arrVpcProductstatus.listIterator();
		while(iterObject.hasNext()){
			VpcProductstatus object = iterObject.next();
			if(object.getId().equals(id))return object.getText();
			
		}
		return "";
	}
	
	public static void AddNew(String text){
		try{
			VpcProductstatus object = new VpcProductstatus();
			object.setText(text);
			VpcProductstatusDAO ObjectDAO = DAOFactory.getInstance().getVpcProductstatusDAO();
			ObjectDAO.save(object);
			arrVpcProductstatus = null;
		}catch(Exception ex){
			
		}
	}
	
	public static void Delete(int id){
		try{
			
			VpcProductstatusDAO ObjectDAO = DAOFactory.getInstance().getVpcProductstatusDAO();
			VpcProductstatus object = ObjectDAO.findById(id);
			ObjectDAO.delete(object);
			arrVpcProductstatus = null;
		}catch(Exception ex){
			
		}
	}
}
